<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>动效按钮</title>
		<style type="text/css">
			a {
				text-decoration: none;
				display: block;
				height: 50px;
				line-height: 50px;
				padding: 0 3em;
				border: 1px solid black;
				font-weight: bold;
				color: black;
				border-radius: 4px;
				/* 水平垂直居中元素两种方法的区别 */
				position: absolute;
				/* top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				margin: auto; */
				/* 当元素的宽度没有,就不成立 */
				top: 50%;
				left: 50%;
				transform: translate(-50%,-50%);
				/* 当元素的宽度没有,用变形来位移,
				避免margin auto自适应带来的bug */
				
			}
			a:hover {
				color: wheat;
				transition: 1s;
			}
			a:hover::before {
				width: 100%;
				transition: .5s;
			}
			a::before {
				content: '';
				display: block;
				width: 0%;
				height: 100%;
				background-color: black;
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
			}
		</style>
	</head>
	<body>
		<a href="#">立即购买</a>
	</body>
</html>
